
class Alg<T extends Comparable>{
    public T func(T[] array){
        T max=array[0];
        for (int i = 1; i < array.length; i++) {
            if(max.compareTo(array[i])<0){
                max=array[i];
            }

        }
        return (T) max;


    }

        }

class Person implements Comparable<Person>{

    private int age;

    public Person(int age){
        this.age=age;
    }

    @Override
    public int compareTo(Person o) {
        return this.age-o.age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                '}';
    }
}




public class 泛型类 {
    public static void main(String[] args) {
        Person[] personlist=new Person[3];
        personlist[0]=new Person(20);
        personlist[1]=new Person(30);
        personlist[2]=new Person(25);
        Alg<Person> alg=new Alg<>();
        Person max=alg.func(personlist);
        System.out.println("the olderst is "+max);


    }
}
